package com.cooper.dao.item;

import java.util.Collection;
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.Insert;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.Update;

import com.cooper.entity.ItemSku;

@DAO
public interface ItemSkuDAO {

	static final String TABLE_NAME = "d_item_sku";
	
	@ReturnGeneratedKeys
	@Insert(tableName=TABLE_NAME)
	Long saveEntity(ItemSku sku) throws Exception;
	
	@Update(tableName=TABLE_NAME)
	boolean updateEntity(ItemSku sku) throws Exception;
	
	@Insert(tableName=TABLE_NAME)
	void saveEntities(List<ItemSku> skuList) throws Exception;
	
	@SQL("select * from d_item_sku t where t.deleted='n' and t.id=:1 ")
	ItemSku loadById(long id) throws Exception;
	
	@SQL("update d_item_sku set deleted='y' where item_id=:1 and id not in (:2) ")
	void deleteSkusNotUsedByItemId(long itemId, Collection<Long> skuIdList);
	
	@SQL("select * from d_item_sku t where t.deleted='n' and t.item_id=:1 order by id asc ")
	List<ItemSku> getItemSkuListByItemId(long itemId) throws Exception;
	
	@SQL("select * from d_item_sku t where t.deleted='n' and t.item_id=:1 and t.properties=:2 ")
	ItemSku getItemSkuByItemIdAndPropKey(Long itemId, String propKey) throws Exception;
}
